<template>
  <div class="app-container home">
    <el-row>      
      <el-col :span="12">
        <el-card :body-style="{ padding: '0px' }">
          <div id="echarts01" ref="echarts01" style="height: 400px"></div>
        </el-card>
      </el-col>      
      <el-col :span="12"></el-col>
    </el-row>
  </div>
</template>

<script>
import { loginSSO,getInfoByAccessToken,getUserInfo  } from "@/api/login";
import { getToken,setToken,setUserInfo,jumpLogin,setRouterList } from '@/utils/auth'
import echarts from "echarts";
import { tongji } from "@/api/system/volunteer";

export default {
  name: "Index",
  data() {
    return {
      // 版本号
      version: "3.8.1",
    };
  },
  methods: {
    goTarget(href) {
      window.open(href, "_blank");
    },
    async init01() {      
      let chartData = [];
      console.log("init01");
      let res = await tongji();
      console.log("tongji");
      if(res.code == 200) {
        chartData=res.data;        
      }
      var myChart = echarts.init(this.$refs.echarts01);
        var option;
        option = {
            title: {
            text: '志愿者状态统计',
            subtext: '志愿者状态统计',
            left: 'center'
          },
          tooltip: {
            trigger: 'item'
          },
          color:['#7FC9A4', '#B7CCF7', '#7296F4','#916fe8','#5eb2f2','#FF9393'],
          legend: {
            orient: 'vertical',
            left: 'left'
          },
          series: [
            {
              name: '数量',
              type: 'pie',
              radius: '50%',
              data: chartData,
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]
        };
        option && myChart.setOption(option);
    }
  },
  mounted() {
      console.log('mounted')
      this.init01();
  },
  async created() {
    // console.log( this.$route.query.code)
    if(this.$route.query && this.$route.query.code) {
      let code = this.$route.query.code

      let token = getToken()
      console.log('token>' + token)
      if(!token) {
        let res = await loginSSO(code)
        console.log('res>' + JSON.stringify(res))
        if(res.code == 200) {
          let token = res.data.data.token
          setToken(token)
          setUserInfo(JSON.stringify(res.data.data))

          this.$store.dispatch('setName', res.data.principal.employee.name)
          this.$store.dispatch('SET_ISSHOWCARD', res.data.principal.employee.isShowCard)


          // localStorage.setItem("menu02",JSON.stringify(res.data.data.authorities))
          localStorage.setItem("menu02",JSON.stringify(res.data.principal.menuList))
          setRouterList()

        }else {
          jumpLogin()
        }
      }
      // else
      // {
      //     let uuid = token;
      //     let { code, ...otherParams } = this.$route.query;
      //     let queryParams = { ...otherParams, uuid };
      //     this.$router.push({ path: this.$route.path, query: queryParams });
      // }
    } else if(this.$route.query && this.$route.query.accessToken) {
      let accessToken = this.$route.query.accessToken
      console.log('accessToken>' + accessToken)

      let res = await getInfoByAccessToken(accessToken)
      if(res.code == 200) {
        let token = res.data.data.token
        setToken(token)
        setUserInfo(JSON.stringify(res.data.data))

        
        this.$store.dispatch('setName', res.data.principal.employee.name)
        this.$store.dispatch('SET_ISSHOWCARD', res.data.principal.employee.isShowCard)

        // localStorage.setItem("menu02",JSON.stringify(res.data.data.authorities))
        localStorage.setItem("menu02",JSON.stringify(res.data.principal.menuList))
        setRouterList()
      }else {
        // jumpLogin()
      }
      
    } else if (this.$route.query && this.$route.query.uuid) {
      let uuid = this.$route.query.uuid
      console.log('uuid>' + uuid)

      let res = await getUserInfo(uuid)
      if(res.code == 200) {
        setToken(uuid)
        setUserInfo(JSON.stringify(res.data))

        this.$store.dispatch('setUuid', uuid)
        this.$store.dispatch('setName', res.data.principal.employee.name)
        this.$store.dispatch('SET_ISSHOWCARD', res.data.principal.employee.isShowCard)
        

        // localStorage.setItem("menu02",JSON.stringify(res.data.authorities))
        localStorage.setItem("menu02",JSON.stringify(res.data.principal.menuList))
        setRouterList()
      }else {
        // jumpLogin()
      }
    } else {
      // jumpLogin()
    }
  },
};
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>

